package com.example.manging;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class StudentSystemDB {
    public static void main(String[] args) {
        ApplicationContext hong;
        hong = new ClassPathXmlApplicationContext("spring_butler.xml");
        User user = (User) hong.getBean("user");
        UserManage userManage = (UserManage) hong.getBean("userManage");
        Score score = (Score) hong.getBean("score");
        ScoreManage scoreManage = (ScoreManage) hong.getBean("scoreManage");
        CouserManage couserManage = (CouserManage) hong.getBean("CouserManage");

        System.out.println(userManage.all());

        user.setNumber("10086");
        user.setPassword("123456");
        user.setIdentity("教师");
        if (userManage.login(user)){
            System.out.println(user.getIdentity()+"登录成功");
            System.out.println("插入202303230000 的学生成绩");
            score.setNumber("202303230000");
            score.setChinser(100.0);
            score.setEnglish(100.0);
            score.setMath(100.0);
            scoreManage.addScore(score);
//            System.out.println("查询学生成绩");
            System.out.println(scoreManage.queryAllScore());
            System.out.println("更新202303230000 的学生成绩");
            scoreManage.updateScore("202303230000",100.0);
            System.out.println("查询修改后的所有学生成绩");
            scoreManage.queryAllScore();
        }
        else {
            System.out.println("登录失败");
            user.setNumber("10086");
            user.setPassword("123456");
            user.setIdentity("教师");
            if (userManage.login(user)){
                System.out.println(user.getIdentity()+"登录成功");
                System.out.println("查询学生成绩");
                scoreManage.queryScoreByNumber("202303230001");
                System.out.println("查询课程");
                couserManage.queryCouser();
                try {
                    System.out.println("选择课程");
                    couserManage.slectCouser("202303230001","moive");
                }catch (RuntimeException e){
                    System.out.println("异常"+e.getMessage());
                }
                finally {
                    System.out.println("查询选择的课程");
                    couserManage.queryCouser();
                }
            }
            else {
                System.out.println("登录失败");
            }
        }
    }
}

